package productions;

import exceptions.ParserException;
import lexico.ErrorTable;
import lexico.SymbolTable;
import lexico.TokenClass;

/**
 * @author heekinho
 */
public class ComandosProduction extends AbstractProductionRule {
    /* Muitos dos métodos irão precisar de algo assim: */

    private static ComandosProduction instance = new ComandosProduction();

    public static ComandosProduction getInstance() {
        return instance;
    }


    /**
     * Regra: comandos : se | enquanto | para | escreva | leia | retorno;
     * @return
     * @throws ParserException
     */
    @Override
    public boolean analyze(SymbolTable st, ErrorTable et) throws ParserException {
        if (SeProduction.getInstance().analyze(st, et)) {
            return true;
        }
        if (EnquantoProduction.getInstance().analyze(st, et)) {
            return true;
        }
        if (ParaProduction.getInstance().analyze(st, et)) {
            return true;
        }
        if (EscrevaProduction.getInstance().analyze(st, et)) {
            return true;
        }
        if (LeiaProduction.getInstance().analyze(st, et)) {
            return true;
        }
        if (RetornoProduction.getInstance().analyze(st, et)) {
            return true;
        }

        return false;
    }

    @Override
    protected void populateFirst() {
        first.add(TokenClass.KEYWORD_SE);
        first.add(TokenClass.KEYWORD_PARA);
        first.add(TokenClass.KEYWORD_ENQUANTO);
        first.add(TokenClass.KEYWORD_LEIA);
        first.add(TokenClass.KEYWORD_ESCREVA);
    }

    @Override
    protected void populateFollow() {
        //from instrucao follow
        follow.add(TokenClass.DELIMITER_CLOSING_CURLY_BRACKET);
    }

}
